package com.springstack.kafka.producer.controller;

import com.exampl.springstack.common.exceptionUtils.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author qiangfanghao
 * @date 2022/7/21
 * kafka 生产者类
 */
@RestController
@RequestMapping("/producer")
public class ProducerController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    /***
     * 发送消息
     * topic:要发送的队列
     * msg:发送的消息
     */
    @PostMapping("/send")
    public ResponseResult send(@RequestBody Map<String,String> map){
        //消息发送
        kafkaTemplate.send(map.get("topic"),map.get("msg"));
        return ResponseResult.ok();
    }


}
